<template>
  <div class="video-list">
    <div class="filter-section">
      <el-select v-model="filter.category" placeholder="选择分类">
        <el-option label="全部" value=""></el-option>
        <el-option label="动画" value="animation"></el-option>
        <el-option label="音乐" value="music"></el-option>
        <el-option label="科技" value="technology"></el-option>
      </el-select>d
    </div>

    <div class="video-grid">
      <div 
        v-for="video in videos" 
        :key="video.id" 
        class="video-card"
        @click="goToDetail(video.id)"
      >
        <div class="thumbnail-wrapper">
          <img :src="video.cover" class="video-thumbnail">
          <div class="duration">{{ video.duration }}</div>
        </div>
        <div class="video-info">
          <h3 class="title">{{ video.title }}</h3>
          <div class="meta">
            <span class="up">{{ video.author }}</span>
            <span class="views">{{ video.views }}观看</span>
          </div>
        </div>
      </div>
    </div>

    <el-pagination
      layout="prev, pager, next"
      :page-size="pagination.pageSize"
      :total="pagination.total"
      @current-change="handlePageChange"
    />
  </div>
</template>

<script>
export default {
  name: 'VideoListView',
  data() {
    return {
      filter: {
        category: '',
        sort: 'hot'
      },
      pagination: {
        current: 1,
        pageSize: 12,
        total: 0
      },
      videos: [
        {
          id: 1,
          title: '测试视频1',
          cover: 'https://via.placeholder.com/300x200',
          duration: '10:30',
          author: 'UP主1',
          views: '1.2万'
        },
        {
          id: 2,
          title: '测试视频2',
          cover: 'https://via.placeholder.com/300x200',
          duration: '5:45',
          author: 'UP主2',
          views: '3.4万'
        }
      ]
    }
  },
  methods: {
    fetchVideos() {
      // TODO: 调用API获取视频列表
      console.log('Fetching videos with filter:', this.filter)
    },
    handlePageChange(page) {
      this.pagination.current = page
      this.fetchVideos()
    },
    goToDetail(id) {
      this.$router.push(`/video/${id}`)
    }
  },
  mounted() {
    this.fetchVideos()
  }
}
</script>

<style scoped>
.video-list {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.filter-section {
  margin-bottom: 20px;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.video-card {
  cursor: pointer;
  transition: transform 0.2s;
}

.video-card:hover {
  transform: translateY(-5px);
}

.thumbnail-wrapper {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.video-thumbnail {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
}

.duration {
  position: absolute;
  right: 5px;
  bottom: 5px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 5px;
  border-radius: 2px;
  font-size: 12px;
}

.video-info .title {
  font-size: 14px;
  margin: 0 0 5px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  font-size: 12px;
  color: #999;
}

.meta span {
  margin-right: 10px;
}
</style>